<template>
	<view>
		<view class="wrap-top" :style="{marginTop: statusBarHeight}">
			<view class="info-bg" v-if="dataInfo.user">
				<image class="avatar" :src="dataInfo.user.avatar" @click.stop="onUser"></image>
				
				<view class="info">
					<text class="title">{{dataInfo.user.nickname}}</text>
					<!-- <view class="hot-bg">
						<image class="hot-img" src="@/static/hot_logo.png"></image>
						
						<text class="hot-value">{{dataInfo.hot}}</text>
					</view> -->
				</view>
				
				<view class="gz-btn" v-if="my_user_id != dataInfo.user.id" @click.stop="onCollection">
					<text class="gz-btn-title">{{dataInfo.is_follow ? "已关注" : "关注"}}</text>
				</view>
			</view>
			
			<view class="zw"></view>
			
			<view class="right-bg" @click.stop="onUserList">
				<view class="people-bg" v-if="rankInfo.user_list.length > 0">
					<block v-for="(item, index) in rankInfo.user_list" :key="index">
						<view class="people-item" v-if="item.user">
							<image class="people-img" :src="item.user.avatar"></image>
						</view>
					</block>
				</view>
				
				<view class="live-people">
					<text class="people-num">{{rankInfo.count}}</text>
				</view>
			</view>
			 
			<view class="close-bg" @click="onClose">
				<image class="close" src="@/static/close.png" ></image>
			</view>
		</view>
	</view>
</template>

<script>
	import storage from '@/utils/storage';
	import {
		addFollow,
		cancelFollow
	} from "@/API/newLive.js";
	import st from "@/utils/showtoast.js";
	
	export default {
		data() {
			return {
				statusBarHeight: uni.getSystemInfoSync()["statusBarHeight"],
				dataInfo: {
					user: {
						
					}
				}, //直播中的数据
				
				rankInfo: {
					user_list: [1,2,3],
					count: 0
				},
				
				my_user_id: storage.getUserID(),
			}
		},
		destroyed() {
			uni.$off("ZBStartLive")
			uni.$off("YHStartLook")
		},
		mounted() {
			/**
			 * 显示直播信息
			 */
			uni.$on("ZBStartLive", (info) => {
				this.dataInfo = storage.getLiveRoomInfo()
				
				this.rankInfo = storage.getRoomRankInfo()
			});
			/**
			 * 用户展示直播信息
			 */
			uni.$on("YHStartLook", () => {
				this.dataInfo = storage.getLiveRoomInfo()
				
				this.rankInfo = storage.getRoomRankInfo()
			});
		},
		/**
		 * 方法
		 */
		methods: {
			/**
			 * 查看主播信息
			 */
			onUser() {
			},
			/**
			 * 关注
			 */
			onCollection() {
				if (this.dataInfo.is_follow) {
					//已关注->未关注
					this.cancelFollowData()
				} else {
					//未关注->已关注
					this.addFollowData()
				}
			},
			//关注
			async addFollowData() {
				let res = await addFollow(this.dataInfo.user.id)
				st.show("关注主播成功")
				this.dataInfo.is_follow = true
				this.$set(this.dataInfo.is_follow)
				storage.setLiveRoomInfo(this.dataInfo)
			},
			//取消关注
			async cancelFollowData() {
				let res = await cancelFollow(this.dataInfo.user.id)
				st.show("取消关注主播")
				this.dataInfo.is_follow = false
				this.$set(this.dataInfo.is_follow)
				storage.setLiveRoomInfo(this.dataInfo)
			},
			/**
			 * 在线列表
			 */
			onUserList() {
				uni.$emit("showLiveUserList")
			},
			/**
			 * 关闭直播
			 */
			onClose() {
				uni.navigateBack()
			},
		},
	}
</script>

<style lang="scss" scoped>
	.wrap-top {
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
	}
	.info-bg {
		margin-left: 30rpx;
		height: 64rpx;
		border-radius: 32rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		overflow: hidden;
		background-color: rgba(0, 0, 0, 0.2);
	}
	.avatar {
		margin-left: 5rpx;
		width: 54rpx;
		height: 54rpx;
		border-radius: 50%;
		overflow: hidden;
	}
	.info {
		margin-left: 10rpx;
		margin-right: 20rpx;
		overflow: hidden;
		display: flex;
		flex-direction: column;
	}
	.gz-btn {
		margin-right: 20rpx;
		width: 80rpx;
		height: 40rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
		border-radius: 20rpx;
		overflow: hidden;
		background-color: orange;
	}
	.gz-btn-title {
		color: white;
		font-size: 20rpx;
	}
	.title {
		color: white;
		font-size: 24rpx;
	}
	.hot-bg {
		flex: 1;
		display: flex;
		flex-direction: row;
		align-items: center;
	}
	.hot-img {
		width: 20rpx;
		height: 20rpx;
	}
	.hot-value {
		margin-left: 6rpx;
		color: white;
		font-size: 18rpx;
	}
	
	.zw {
		flex: 1;
		overflow: hidden;
	}
	
	.right-bg {
		margin-right: 20rpx;
		overflow: hidden;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: flex-end;
	}
	.people-bg {
		margin-left: 12rpx;
		margin-right: 12rpx;
		overflow: hidden;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: flex-end;
	}
	.people-item {
		width: 55rpx;
		height: 55rpx;
		margin-left: 10rpx;
		overflow: hidden;
	}
	.people-img {
		width: 55rpx;
		height: 55rpx;
		border-radius: 50%;
		overflow: hidden;
	}
	
	.live-people {
		height: 56rpx;
		background-color: rgba(0, 0, 0, 0.18);
		border-radius: 28rpx;
		overflow: hidden;
		display: flex;
		flex-direction: row;
		align-items: center;
	}
	.people-num {
		margin-left: 20rpx;
		margin-right: 20rpx;
		font-size: 24rpx;
		color: white;
	}
	.close-bg {
		margin-right: 20rpx;
		width: 45rpx;
		height: 88rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.close {
		width: 31rpx;
		height: 31rpx;
	}
</style>